`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    18:09:19 06/08/2014 
// Design Name: 
// Module Name:    score_update 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module score_update(
  input clock, 
  input [3:0] ones, tens, hundreds, lives,
  input [9:0] pixel_row, pixel_coloumn,
  input [1:0] ROM_data_1, ROM_data_2, ROM_data_3, ROM_data_life_1,
  
  output [11:0] ROM_addr_1, ROM_addr_2 , ROM_addr_3 , ROM_addr_life_1, 
  output [1:0] icon_1, icon_2, icon_3, icon_life_1
    );
	 
	 wire [9:0] LocX_1 = 10`d38; 
	 wire [9:0] LocY_1 = 10'd0;
	 wire [9:0] LocX_1 = 10`d46; 
	 wire [9:0] LocY_1 = 10'd0;
	 wire [9:0] LocX_1 = 10`d54; 
	 wire [9:0] LocY_1 = 10'd0;
	 wire [9:0] LocX_life_1 = 10`d99; 
	 wire [9:0] LocY_life_1 = 10'd0;
	 //wire [9:0] LocX_life_2 = 10`d108; 
	 //wire [9:0] LocY_life_2 = 10'd0;
	 //wire [9:0] LocX_life_3 = 10`d117; 
	 //wire [9:0] LocY_life_3 = 10'd0;
	 
	 wire signed [9:0] x_1_coord;
	 wire signed [9:0] y_1_coord;
    wire signed [9:0] x_2_coord;
	 wire signed [9:0] y_2_coord;
    wire signed [9:0] x_3_coord;
	 wire signed [9:0] y_3_coord;
    wire signed [9:0] x_life_1_coord;
	 wire signed [9:0] y_life_1_coord;
	 //wire signed [9:0] x_life_2_coord;
	 //wire signed [9:0] y_life_2_coord;
	 //wire signed [9:0] x_life_3_coord;
	 //wire signed [9:0] y_life_3_coord;
	

	//adding offset of 14 which helps in centering the BOT about the black line
	assign x_1_coord   	  	=	(pixel_column	-	{LocX_1, 1'b0, 1'b0}	+ 14);		
	assign y_1_coord	      =	(pixel_row		-	{LocY_1, 1'b0, 1'b0}	+ 14);
	assign x_2_coord		   =	(pixel_column	-	{LocX_2, 1'b0, 1'b0}	+ 14);		
	assign y_2_coord		   =	(pixel_row		-	{LocY_2, 1'b0, 1'b0}	+ 14);
	assign x_3_coord		   =	(pixel_column	-	{LocX_3, 1'b0, 1'b0}	+ 14);		
	assign y_3_coord		   =	(pixel_row		-	{LocY_3, 1'b0, 1'b0}	+ 14);
	assign x_life_1_coord	=	(pixel_column	-	{LocX_life_1, 1'b0, 1'b0}	+ 14);		
	assign y_life_1_coord	=	(pixel_row		-	{LocY_life_1, 1'b0, 1'b0}	+ 14);
	//assign x_life_2_coord	=	(pixel_column	-	{LocX_life_2, 1'b0, 1'b0}	+ 14);		
	//assign y_life_2_coord	=	(pixel_row		-	{LocY_life_2, 1'b0, 1'b0}	+ 14);
	//assign x_life_3_coord	=	(pixel_column	-	{LocX_life_3, 1'b0, 1'b0}	+ 14);		
	//assign y_life_3_coord	=	(pixel_row		-	{LocY_life_3, 1'b0, 1'b0}	+ 14);
	//Upper 3 bits in the ROM address decide the orientation to display
	//									 -------------------------------------------
	//	FORMAT OF ROM addrESS:	| DIGIT/LIFE | Y COORDINATE | x COORDINATE |
	//									 -------------	-----------------------------
	assign ROM_addr_1			=	{ones [3:1], y_1_coord[3:1], x_1_coord[3:1]};
	assign ROM_addr_2			=	{tens [3:1], y_2_coord[3:1], x_2_coord[3:1]};
	assign ROM_addr_3			=	{hundreds [3:1], y_3_coord[3:1], x_3_coord[3:1]};
	assign ROM_addr_life_1	=	{lives [3:1], y_life_1_coord[3:1], x_life_1_coord[3:1]};
	//assign ROM_addr_life_2	=	{lives [3:1], y_life_2_coord[3:1], x_life_2_coord[3:1]};
	//assign ROM_addr_life_3	=	{lives [3:1], y_life_3_coord[3:1], x_life_3_coord[3:1]};
	
	always @(*)
	begin 
	 //Display an icon of area 32 x 32 pixels around the location indicated by the BOTSIM
	 //The icon would not be centered around the black line and an offset needs to be added 
	 //to center the BOT about the black line which is done above
	 if(x_coord >= 0 && x_coord <= 31 && y_coord >= 0 && y_coord <= 31)
	 begin
		icon_1[1:0] = ROM_data;			//select colour to be displayed from the ROM			
	 icon_2[1:0] = ROM_data;
	 icon_3[1:0] = ROM_data;
	 icon_life_1[1:0] = ROM_data;
	 
	 end
	 else		
	 begin
		icon_1 [1:0] = 2'b00;						//else make the icon transparent to show the underlying MAP
	   icon_2 [1:0] = 2'b00;
		icon_3 [1:0] = 2'b00;
		icon_life_1 [1:0] = 2'b00;
	 end
	end			
			
	 


endmodule
